<?php
function edits( )
{
				global $db;
				$db->query( "SELECT * FROM tun2_adminset WHERE id=".$_GET['id'] );
				if ( $db->next_record( ) )
				{
								echo "<script language=\"javascript\" src=\"inc/js.js\"></script>\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n<form action=\"Admin_Set.php?Action=edit\" method=\"post\" onSubmit=\"return Validator.Validate(this,3)\">\r\n<input name=\"id\" type=\"hidden\" value=\"";
								echo $db->Record['id'];
								echo "\"/>\r\n  <tr>\r\n    <td width=\"15%\" align=\"right\">用户名：</td>\r\n    <td> <input name=\"name\" type=\"text\" value=\"";
								echo $db->Record['name'];
								echo "\" size=\"40\" dataType=\"LimitB\" min=\"3\" max=\"20\" msg=\"用户名必须在3,20个字节之内\"/></td>\r\n    </tr>\r\n  <tr>\r\n    <td align=\"right\"> 密码：</td>\r\n    <td><input  name=\"password\" type=\"password\" value=\"\" size=\"40\" dataType=\"LimitB\" min=\"6\" max=\"20\" msg=\"密码必须在6,20个字节之内\"/></td>\r\n    </tr>\r\n  <tr>\r\n    <td align=\"right\">重复密码： </td>\r\n    <td><input  name=\"password2\" type=\"password\" value=\"\" size=\"40\" dataType=\"Repeat\" to=\"password\" msg=\"两次输入的密码不一致\"/></td>\r\n  </tr>\r\n  <tr align=\"center\">\r\n    <td colspan=\"2\"><input type=\"submit\" name=\"Submit_edit\" value=\"确定修改\" ></td>\r\n  </tr>\r\n</form>\r\n</table>\r\n";
				}
}

include( "inc/header.php" );
login_check( );
echo "<body>\r\n<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n  <tr>\r\n    <td><a href=\"Admin_Set.php\"> 管理员管理</a> ｜ <a href=\"Admin_Set.php?Action=add\">添加新管理员</a></td>\r\n  </tr>\r\n</table>\r\n<br>\r\n";
switch ( $_GET['Action'] )
{
case "add" :
				echo "<script language=\"javascript\" src=\"inc/js.js\"></script><table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\"><form action=\"Admin_Set.php?Action=adds\" method=\"post\" onSubmit=\"return Validator.Validate(this,3)\"><input name=\"id\" type=\"hidden\" value=\"\" /><tr><td width=\"15%\" align=\"right\">用户名：</td><td> <input name=\"name\" type=\"text\" value=\"\" size=\"40\" dataType=\"LimitB\" min=\"3\" max=\"20\" msg=\"用户名必须在3,20个字节之内\"/></td></tr><tr><td align=\"right\"> 密码：</td><td><input  name=\"password\" type=\"password\" value=\"\" size=\"40\" dataType=\"LimitB\" min=\"6\" max=\"20\" msg=\"密码必须在6,20个字节之内\" /></td></tr><tr><td align=\"right\">重复密码： </td><td><input  name=\"password2\" type=\"password\" value=\"\" size=\"40\" dataType=\"Repeat\" to=\"password\" msg=\"两次输入的密码不一致\" /></td></tr><tr align=\"center\"><td colspan=\"2\"><input type=\"submit\" name=\"Submit_edit\" value=\"确定修改\" ></td></tr></form></table>";
				break;
case "adds" :
				if ( function_exists( "date_default_timezone_set" ) )
				{
								date_default_timezone_set( "Hongkong" );
				}
				@$lastime = @date( "Y-m-d H-i-s" );
				@$GLOBALS['_POST']['password'] = md5( @md5( $_POST['password'] ) );
				$db->query( "INSERT INTO tun2_adminset (name,password,lasttime,lastip) VALUES \r\n\t\t\t\t\t('".$_POST['name']."','{$_POST['password']}','{$lastime}','".getip( )."')" );
				addlog( "添加管理员", $_SESSION['user_name'] );
				admin_showerr( "<li>添加管理员成功</li>", "Admin_Set.php", 1 );
				break;
case "edits" :
				edits( );
				break;
case "edit" :
				if ( $_POST['password2'] != $_POST['password'] )
				{
								echo "<script>alert(\"两次输入密码不一致,请重新输入\");</script>";
								work_back( "<br>正在返回上一页", "Admin_Set.php?Action=edits&id=".$_POST['id'] );
								exit( );
				}
				@$GLOBALS['_POST'][password] = md5( @md5( $_POST[password] ) );
				$db->query( "UPDATE tun2_adminset SET name='".$_POST['name']."',password='{$_POST['password']}' WHERE id={$_POST['id']}" );
				addlog( "修改管理员", $_SESSION['user_name'] );
				admin_showerr( "<li>修改管理员成功</li>", "Admin_Set.php", 1 );
				break;
case "del" :
				$db->query( "DELETE FROM tun2_adminset WHERE id=".$_GET['id'] );
				addlog( "删除管理员", $_SESSION['user_name'] );
				admin_showerr( "<li>删除管理员成功</li>", "Admin_Set.php", 1 );
				break;
default :
				$db->query( "SELECT * FROM tun2_adminset" );
				echo "<table width=\"98%\" border=\"1\" align=\"center\" cellpadding=\"5\" cellspacing=\"0\" class=\"table\">\r\n<form action=\"Admin_Set.php\" method=\"post\" name=\"form";
				echo $db->Record['id'];
				echo "\">\r\n  <tr align=\"center\">\r\n    <td><strong>管理员名称</strong></td>\r\n    <td width=\"20%\"><strong>上次登录IP</strong></td>\r\n    <td width=\"20%\"><strong>上次登录时间</strong></td>\r\n    <td width=\"12%\"><strong>操作</strong></td>\r\n  </tr>\r\n";
				while ( $db->next_record( ) )
				{
								echo "  <tr>\r\n    <td width=\"35%\" height=\"30\">";
								echo $db->Record['name'];
								echo "</td>\r\n    <td align=\"center\">";
								echo $db->Record['lastip'];
								echo "</td>\r\n    <td align=\"center\">";
								echo $db->Record['lasttime'];
								echo "</td>\r\n    <td align=\"center\"><a href=\"Admin_Set.php?Action=edits&id=";
								echo $db->Record['id'];
								echo "\">修改</a> ｜<a href=\"Admin_Set.php?Action=del&id=";
								echo $db->Record['id'];
								echo "\">删除</a></td>\r\n  </tr>\r\n";
				}
				echo "</form>\r\n</table>\r\n<br />\r\n";
}
echo "</body>\r\n</html>";
?>
